package scrum.client.project;

import scrum.client.common.TooltipBuilder;

public class DeleteProjectGroupAction extends GDeleteProjectGroupAction {

	public DeleteProjectGroupAction(scrum.client.project.ProjectGroup projectGroup) {
		super(projectGroup);
	}

	@Override
	public String getLabel() {
		return "Delete";
	}

	@Override
	protected void updateTooltip(TooltipBuilder tb) {
		tb.setText("Delete this Project Group permanently.");
		if (!projectGroup.getProject().isProductOwner(getCurrentUser()))
			tb.addRemark(TooltipBuilder.NOT_PRODUCT_OWNER);
	}

	@Override
	public boolean isExecutable() {
		return true;
	}

	@Override
	public boolean isPermitted() {
		if (!projectGroup.getProject().isProductOwner(getCurrentUser())) return false;
		return true;
	}

	@Override
	protected void onExecute() {
		projectGroup.getProject().deleteProjectGroup(projectGroup);
		addUndo(new Undo());
	}

	class Undo extends ALocalUndo {

		@Override
		public String getLabel() {
			return "Undo Delete " + projectGroup.getLabel();
		}

		@Override
		protected void onUndo() {
			getDao().createProjectGroup(projectGroup);
		}

	}
}